package com.itheima.com.Dao;

import com.itheima.com.Controller.BaseStudentController;
import com.itheima.com.domain.Student;

import java.util.ArrayList;

public class OtherStudentDao implements BaseStudentDao {
    private static ArrayList<Student> students=new ArrayList();
    static {
        Student stu1 = new Student("heima001", "张三", "23", "1999-11-11");
        Student stu2 = new Student("heima002", "李四", "24", "1998-11-11");
        students.add(stu1);
        students.add(stu2);
    }
    public  Student[] getAllStudent() {
        Student[] stu=new Student[students.size()];
        for (int i = 0; i < stu.length; i++) {
            stu[i]=students.get(i);
        }
        return stu;
    }

    public  void deleteById(String did) {
        int index = getIndex(did);
        students.remove(index);
    }
public   int getIndex(String id){
        int index=-1;
    for (int i = 0; i < students.size(); i++) {
        Student student=students.get(i);
        if (student!=null&&student.getId().equals(id)){
            index=i;
            break;
        }
    }
    return index;
}



    public  void addStudent(Student stu) {
       students.add(stu);
    }

    public void updateStudent(String uid, Student newStu) {
        int index = getIndex(uid);
        students.set(index,newStu);
    }
}
